package com.window;

import com.event.ChangeOwnEvent;

import javax.swing.*;
import java.awt.*;

public class ChangeOwnPass extends JFrame {
    FlowLayout flowlayout;
    JLabel password;
    public static JPasswordField passwordtext;
    JButton change;


    final int WIDTH = 250;//框架宽度
    final int HEIGHT = 100;//框架高度

    public ChangeOwnPass() {
        init();
        setVisible(true);//设置窗口可视化
        setResizable(false);//设置窗口大小不可变
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);//设置默认关闭方式
        validate();//让组件生效
        allevent();
    }

    void init() {
        flowlayout = new FlowLayout(FlowLayout.CENTER);//布局居中
        this.setLayout(flowlayout);
        //设置窗口大小与位置
        Toolkit kit = Toolkit.getDefaultToolkit();
        Dimension screenSize = kit.getScreenSize();
        int width = screenSize.width;
        int height = screenSize.height;
        int x = (width - WIDTH) / 2;
        int y = (height - HEIGHT) / 2;
        this.setBounds(x, y, WIDTH, HEIGHT);//设置窗口位置与大小

        password = new JLabel("新密码");
        passwordtext = new JPasswordField(15);
        change = new JButton("更改密码");

        this.add(password);
        this.add(passwordtext);
        this.add(change);
    }

    void allevent() {
        ChangeOwnEvent a = new ChangeOwnEvent();
        change.addActionListener(a);
    }
}
